package com.dzf.controller;


import com.dzf.entity.BookType;
import com.dzf.entity.RespJson;
import com.dzf.service.BookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author DZF
 * 商品类型的 后台模块
 */
@RestController
@RequestMapping("/api/adm/type")
public class AdmBookTypeController {
    @Autowired
    BookTypeService bookTypeService;

    /**
     * 类型全查询
     * @return 所有的类型
     */
    @RequestMapping("/findAll")
    public RespJson findAll(){
        return RespJson.pack(200,"OK",bookTypeService.findAll());
    }

    /**
     * 查询某个类型的详细信息
     * @param id 类型ID
     * @return  类型的信息
     */
    @RequestMapping("/findById/{id}")
    public RespJson findById(@PathVariable("id") int id){
        return RespJson.pack(200,"",bookTypeService.findById(id));
    }

    /**
     * 类型添加
     * @param bookType 商品类型的实体类
     * @return 添加后查询商品类型
     */
    @PostMapping("/add")
    public RespJson amend(@RequestBody BookType bookType)
    {
        bookTypeService.amend(bookType);
        return RespJson.pack(200,"添加成功",bookTypeService.findAll());
    }


}
